package stud.mpgame.network.util;

import org.apache.mina.core.buffer.IoBuffer;
import stud.mpgame.network.Message;
import stud.mpgame.network.MessageDescription;
import stud.mpgame.network.UserObject;

public class ResponseUserObject extends UserObject {

    private MessageDescription messageDescription;
    private int serialNumber;
    private int sentTime;
    private int receivedTime;

    public ResponseUserObject() {}

    public ResponseUserObject(Message message) {
        this.messageDescription = message.getMessageDescription();
        this.serialNumber = message.getSerialNumber();
        this.sentTime = message.getSentTime();
        this.receivedTime = message.getReceivedTime();
    }

    public int getReceivedTime() {
        return receivedTime;
    }

    public int getSentTime() {
        return sentTime;
    }

    public int getSerialNumber() {
        return serialNumber;
    }

    public MessageDescription getMessageDescription() {
        return messageDescription;
    }

    @Override
    public void readExternal(IoBuffer buffer, Message owner) {
        int messageDescriptionID = buffer.getInt();
        this.messageDescription = MessageDescription.getMessageDescription(messageDescriptionID);
        this.serialNumber = buffer.getInt();
        this.sentTime = buffer.getInt();
        this.receivedTime = buffer.getInt();
    }

    @Override
    public void writeExternal(IoBuffer buffer, Message owner) {
        buffer.putInt(messageDescription.getID());
        buffer.putInt(serialNumber);
        buffer.putInt(sentTime);
        buffer.putInt(receivedTime);
    }

}
